from stacking.loader.processing.sim.simulation import SimObserver

        
class MaxHeight(SimObserver):
    """This observer computes the maximum height reached by any stack during the simulation. This 
    value can be used as an estimate of warehouse height."""
    def init(self, warehouse):
        SimObserver.init(self, warehouse)
        self.max_height = 0.0
        
    def pre_execute(self, crane, action):
        if action.internal:  # update maximum height only in actions involving stacks
            H = self.warehouse.objects[action.place].height
            if action.is_putdown:
                for item_id in action.items:
                    H += self.items[item_id].thickness
            self.max_height = max(self.max_height, H)
            
    def end(self):
        return self.max_height
        
